/* 
 * Copyright 2013 Sébastien Mouquet.
 * 
 * This file is part of ECovoiturage.
 * 
 * ECovoiturage is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ECovoiturage is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ECovoiturage. If not, see http://www.gnu.org/licenses/.
 */
package com.smouquet.ecovoiturage.ui;

import com.vaadin.server.Page;
import com.vaadin.ui.Notification;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Classe utilitaire pour les notifications.
 * 
 * @author sebastien.mouquet
 */
public class NotificationUtil
{
    
    public static void showExceptionNotification(Exception ex)
    {
        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        
        StringBuilder msg = new StringBuilder();
        msg.append(ex.getMessage()).append("<br><br>");
        msg.append(sw.toString());
        
        Notification notification = new Notification("Erreur inconnue<br>", msg.toString(), Notification.Type.ERROR_MESSAGE, true);
        notification.show(Page.getCurrent());
    }
    
    public static void showWarningNotification(String message)
    {
        Notification notification = new Notification("Attention<br>", message, Notification.Type.WARNING_MESSAGE, true);
        notification.show(Page.getCurrent());
    }
    
    public static void showInformationNotification(String message)
    {
        Notification notification = new Notification("Information<br>", message, Notification.Type.HUMANIZED_MESSAGE, true);
        notification.show(Page.getCurrent());
    }
    
}
